package com.cjzuji.rental.controller.order;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cjzuji.rental.mapper.OrderMapper;
import com.cjzuji.rental.mapper.RequestMapper;
import com.cjzuji.rental.pojo.RequestHeard;
import com.cjzuji.rental.service.ErSQLYPService;
import com.cjzuji.rental.service.QianLianYPService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
@RestController
@RequestMapping("/order/erSQL")
@Api(tags = "二手谦莲优品订单列表")
//@Component
public class ErSQLYPController {
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    RequestMapper requestMapper;
    @Autowired
    ErSQLYPService erSQLYPService;
    private static final Logger logger = LoggerFactory.getLogger(ErSQLYPController.class);

    //所有数据
    @GetMapping("/yplist")
    @ApiOperation(value = "获取所有订单", notes = "二手谦莲优品所有订单列表")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    public List<Map<String, Object>> getOrderList(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String accesstoken = requestHeard.getErsqlypaccesstoken();
            String authorization = requestHeard.getErsqlypauthorization();
            List<Map<String, Object>> result = erSQLYPService.getOrderssList(accesstoken, authorization);
            return result;
        } catch (Exception e) {
            logger.error("获取二手谦莲所有订单列表详情失败");
            return null;
        }

    }

    //获取租用中的数据
    @PutMapping("/upDateBill")
    //@Scheduled(fixedRate = 60 * 60 * 2000)
    @ApiOperation(value = "获取租用中订单", notes = "获取租用中订单")
    public List<Map<String, Object>> upDateBill(){
        //从数据库获取
        try {
            QueryWrapper<RequestHeard> queryWrapper = new QueryWrapper<>();
            RequestHeard requestHeard = requestMapper.selectOne(queryWrapper);
            String accesstoken = requestHeard.getErsqlypaccesstoken();
            String authorization = requestHeard.getErsqlypauthorization();
            List<Map<String, Object>> result = erSQLYPService.upDateBillList(accesstoken, authorization, "useList");
            return result;
        } catch (Exception e) {
            logger.error("获取二手谦莲租用中订单列表详情失败");
            return null;
        }
    }
}
